#include <iostream>

int trans(std::string num)
{
    int real_num = 0;
    int k = num.size();
    for (int i = 0; i < k; i++)
    {
        int r = num[i] - '0';
        if (r > 4)
            r--;
        real_num = real_num * 9 + r;
    }

    return real_num;
}

int main()
{
    std::string num;
    std::cin >> num;

    int real_num = trans(num);

    std::cout << real_num << std::endl;

    return 0;
}